﻿using BW.MesProject.Public.ErrorCode;
using BW.MesProject.WareHouse.Application;
using BW.MesProject.WareHouse.Domain;
using BW.MesProject.WareHouse.Infrastructure;
using BW.MesProject.WareHouse.Infrastructure.Dto.Input;
using BW.MesProject.WareHouse.Infrastructure.Dto.OutPut;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace BW.MesProject.WareHouse.Host.Controllers
{
    /// <summary>
    /// 工艺管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        // GET: api/<ProcessController>
        private readonly IProcessServices ProcessServices;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ProcesServices"></param>
        public ProcessController(IProcessServices ProcesServices)
        {
            this.ProcessServices = ProcesServices;
        }

        /// <summary>
        /// 添加工艺
        /// </summary>
        /// <param name="input">包含工序信息的输入参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddProcess([FromBody] ProcessInput input)
        {
            return await ProcessServices.AddProcessNew(input.Process, input.ProcessFile, input.ProcessItem);
        }

        /// <summary>
        /// 查询工艺列表
        /// </summary>
        /// <param name="input">查询参数</param>
        /// <returns>工序管理列表</returns>
        [HttpGet]
        public ApiResult<List<ProcessOut>> GetProcessList([FromQuery] QryInput input)
        {
            return ProcessServices.GetProcessList(input);
        }
        /// <summary>
        /// 获取工艺详情
        /// </summary>
        /// <param name="processId">工序管理ID</param>
        /// <returns>工序管理详情</returns>
        [HttpGet]
        public ApiResult<ProcessOut> GetProcessDetail(string processId)
        {
            return ProcessServices.GetProcessDetail(processId);
        }

        /// <summary>
        /// 获取工艺文件详情
        /// </summary>
        /// <param name="PRId">工序管理ID</param>
        /// <returns>工序管理详情</returns>
        [HttpGet]
        public ApiResult<List<ProcessFileOut>> GetProcessFileList(string PRId)
        {
            return ProcessServices.GetProcessFileList(PRId);
        }

        /// <summary>
        /// 获取工艺明细详情
        /// </summary>
        /// <param name="PRId">工序管理ID</param>
        /// <returns>工序管理详情</returns>
        [HttpGet]
        public ApiResult<List<ProcessItemOut>> GetProcessItemList(string PRId)
        {
            return ProcessServices.GetProcessItemList(PRId);
        }


        /// <summary>
        /// 修改工艺管理信息
        /// </summary>
        /// <param name="input">包含工序管理信息的输入参数</param>
        /// <returns>修改结果</returns>
        [HttpPost]
        public async Task<ApiResult<bool>> UpdateProcess([FromBody] ProcessInput input)
        {
            return await ProcessServices.UpdateProcess(input.Process, input.ProcessFile, input.ProcessItem);
        }

        /// <summary>
        /// 删除工艺管理信息
        /// </summary>
        /// <param name="processId">工序管理ID</param>
        /// <returns>删除结果</returns>
        [HttpDelete]
        public ApiResult<bool> DeleteProcess(string processId)
        {
            return ProcessServices.DeleteProcess(processId);
        }

        /// <summary>
        /// 查询编码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<int> GetCode(string Id, string name)
        {
            return ProcessServices.GetCode(Id, name);
        }
    }
}
